package net.aiion.weave.impl.routing;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import net.aiion.weave.spi.routing.Route;

public class RouteImpl implements Route
{
    private final Collection<String> routeTokens;

    private String routeExtension;

    // private String routeFragment;

    public RouteImpl() {
        routeTokens = new ArrayList<>();
    }

    public void addToken(final String aRouteToken) {
        routeTokens.add(aRouteToken);
    }

    @Override
    public Collection<String> getTokens() {
        return Collections.unmodifiableCollection(routeTokens);
    }

    public void setExtension(final String aRouteExtension) {
        routeExtension = aRouteExtension;
    }

    // public void setFragment(final String aRouteFragment) {
    // routeFragment = aRouteFragment;
    // }

    @Override
    public String getExtension() {
        return routeExtension;
    }

    @Override
    public String toString() {
        final StringBuilder stringBuilder = new StringBuilder();
        for (String routeToken : routeTokens) {
            stringBuilder.append('/');
            stringBuilder.append(routeToken);
        }
        stringBuilder.append('.');
        stringBuilder.append(routeExtension);
        return stringBuilder.toString();
    }
}
